package com.dianrui.fmi.activity;

import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.dianrui.fmi.R;
import com.dianrui.fmi.adapter.BigImagePagerAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 查看大图
 */
public class BigImageActivity extends BaseActivity {
    private int position;
    private List<String> imgList;
    private BigImagePagerAdapter viewPagerAdapter;
    private ViewPager.OnPageChangeListener onPageChangeListener;

    @BindView(R.id.act_big_image_tv_adtitle)
    TextView tvAdtitle;
    @BindView(R.id.act_big_image_vp_icons)
    ViewPager vpIcons;

    @Override
    public int getContentViewId() {
        return R.layout.act_big_image;
    }

    @Override
    public void initView() {
        if (getIntent() != null && getIntent().getExtras() != null) {
            imgList = (List<String>) getIntent().getExtras().getSerializable("data");
            position = getIntent().getIntExtra("current", -1);
        }
        if (imgList.size() > 0) {
            tvAdtitle.setText(1 + "/" + (imgList.size()));
        }
        onPageChangeListener = new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (imgList.size() > 0) {
                    tvAdtitle.setText(position + 1 + "/" + (imgList.size()));
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        };

        viewPagerAdapter = new BigImagePagerAdapter(this);
        vpIcons.setCurrentItem(5);//设置缓存view 的个数
        vpIcons.setAdapter(viewPagerAdapter);
        vpIcons.addOnPageChangeListener(onPageChangeListener);
        viewPagerAdapter.setOnItemClickLinsenter(new BigImagePagerAdapter.OnItemClickLinsenter() {
            @Override
            public void click() {
                finish();
            }
        });
        viewPagerAdapter.updata(imgList);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        vpIcons.removeOnPageChangeListener(onPageChangeListener);
    }



    @OnClick(R.id.act_big_image_balck)
    public void onViewClicked() {
        finish();
    }
}
